<!--AppSuperRootRegister:LendingRegisterView的组件管理者-->
<template>
  <AppSuperRoot/>
</template>
<script>
import {onBeforeMount, onBeforeUnmount, onMounted, provide, reactive, ref, watch} from "vue";
import AppSuperRoot from "@/views/lending/App/AppSuperRoot.vue";
import CatMedicalRecord from "@/views/lending/form/CatMedicalRecord.vue";

import mitt from '@/views/lending/utils/mitt';
import CryptoJS from "crypto-js";

export default {
  name: "LendingRegisterView",
  components:{AppSuperRoot,CatMedicalRecord},
  setup(){

    //cardSearchField:搜索框字段控制
    const cardSearchField = ref([
      {"borrowerName":"借阅人"},
      {"medicalRecord":"病案号"},
      {"hospitaLization":"住院号"},
      {"medicalRecordStatus":"病案状态"},
      {"dataPicker":"申请时间"},
    ])
    provide("cardSearchField",cardSearchField)
    //cardSearchValue:搜索框字段值控制
    const cardSearchValue = ref([
      {"medicalRecordStatus":['待审核','已审核']}
    ])
    provide("cardSearchValue",cardSearchValue)
    //声明组件出处
    provide("LendingWhoView","LendingRegisterView")
    //表单字段控制
    const mainFormField = ref([
      // {'病案号':''},
      // {'住院号':''},
      // {'患者姓名':''},
      {'id':'brId'},//TODO:新增
      {'借阅人':'brBorrowerName'},
      {'借阅日期':'brEstimateBorrower'},
      {'归还日期':'brEstimateRestitution'},
      {'病案状态':'brMedicalRecordStatus'},
      {'登记时间':'brEnroll'},
      {'操作员':'brOperator'},
      {'借阅原因':'brReason'},
    ])
    provide("mainFormField",mainFormField)
    //病案状态的值规则控制
    const recordStatusValue = ref([
      {"0":'待审核'},
      {"1":'已审核'},
      {"2":'已驳回'},
      {"3":'已取消'},
    ])
    provide("recordStatusValue",recordStatusValue)
    //病案状态的颜色规则控制
    const recordStatusColor = ref([
      {"待审核":'color:#FA6A1C'},
      {"已审核":'color:#00A76F'},
      {"已驳回":'color:red'},
      {"已取消":'color:#7A7A7A'},
    ])
    provide("recordStatusColor",recordStatusColor)
    //rightShow:控制各组件所支持的功能规则
    const rightValue = ref([
      '编辑','取消登记','查看'
    ])
     provide("rightValue",rightValue)
    //rightShow:控制各组键所支持的功能展示规则
     const rightShow =ref([
       {'待审核':['编辑','取消登记']},
       {'已审核':['查看']},
       {'已驳回':['查看']},
     ])
     provide("rightShow",rightShow)
    //rightColor:控制各组件所支持功能的颜色展示规则
    const rightColor = ref([
      {"编辑":'color:#0468FF'},
      {"取消登记":'color:#EC2121'},
      {"查看":'color:#0468FF'},

    ])
    provide("rightColor",rightColor)

    //密钥
    const secretKey = ref('')

    //catFieldShow:查看组件数据控制
    const catFieldShow = ref([
      {'targetName':'LendingRegisterView'},
      {'title':'查看登记'},
      {'patientInfo':['病案号','住院号','患者姓名','性别','年龄','住院病区','入院时间','出院时间','出院诊断']},
      {'borrowInfo':['借阅人','借阅日期','归还日期','操作员','登记时间','借阅原因','驳回理由']},
      {'specificFunctions':['编辑','取消登记']},
      {'specificColor':[{"已审核":'color:#0468FF'},{"编辑":['border-color:#0460FF','color:#0468FF']},
          {'已驳回':'color:red'},
          {"取消登记":['border-color:#7F7F7F7F','color:#7F7F7F7F']},
        ]},
      {'routerGoTo':[{'返回':'/lending/lendingRegister/home'}]},
      {'fieldMap':[
          {'借阅人':'brBorrowerName'},
          {'借阅日期':'brEstimateBorrower'},
          {'归还日期':'brEstimateRestitution'},
          {'登记时间':'brEnroll'},
          {'操作员':'brOperator'},
          {'借阅原因':'brReason'},
          {'病案状态':'brMedicalRecordStatus'},
          {'驳回理由':'brRejectReason'},
        ]},
      {'recordStatusValue':[{"0":'待审核'}, {"1":'已审核'},{"2":"已驳回"}]},
      {'rightShow':[
          {'已审核':['编辑','取消登记']}
        ]}
    ])
    //catUrl:接口地址控制
    const catUrl = ref('/lending/lendingRegister/record')
    //catControlShow:界面展示控制
    provide('catControlShow',[catUrl,secretKey,JSON.stringify(catFieldShow.value)])
    //newInFoPost：新增登记发送post数据
    const browInFoPost = ref({
      "brBorrowerName": "",
      "brEstimateBorrower": "",
      "brEstimateRestitution": "",
      "brReason": "",
    })
    //newBrowControl：新建组件数据控制
    const newBrowControl = ref([
      {"browInFoMap":[
          {"brBorrowerName": "name",},
          {"brEstimateBorrower": "startDate"},
          {"brEstimateRestitution": "endDate"},
          {"brReason": "enroll",},
        ]},
      {'browInFoPost':browInFoPost}

    ])
    //传输新建组件数据控制
    provide('newBrowControl',newBrowControl.value)
    // getSecretKey：更新秘钥规则
    function getSecretKey() {
      const currentTime = new Date().getTime();
      const baseKey = 'LendingRegisterView'; // 基础密钥
      const newSecretKey = `${baseKey}-${currentTime}`;
      secretKey.value = CryptoJS.MD5(newSecretKey).toString();
    }
    onMounted(()=>{
      // 页面加载时初始化 secretKey
      getSecretKey()
    })
    //定时更新secretKey
    setTimeout(getSecretKey, 30000)
  }
}
</script>

<script setup>


</script>

<style scoped>

</style>